<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <title>增加一条记录</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <script type="text/javascript"
            src="${pageContext.request.contextPath}/js/jquery-1.11.3.min.js">
        </script>
        <script type="text/javascript">
            function verifyStuId() {
            // 获取输入的学生学号
            var stuId = $("#stuId").val();
            if (stuId == null || stuId == "") {
                alert("学号不能为空！");
                return;
            }
            $.ajax({
                        url: "${pageContext.request.contextPath}/student/verifyStuId",
                        type: "post",
                        contentType: "application/json;charset=UTF-8",
                        // data表示发送的数据
                        data: JSON.stringify({
                            stuId: stuId
                        }),
                        //定义回调响应的数据格式为字符串,不能写成json,否则会解析数据错误
                        dataType: "text",
                        //成功响应的结果
                        success: function(data) {
                            if (data == "yes") {
                                alert("学号已被使用！");
                            } else {
                                alert("学号可以使用！");
                            }
                        },
                        //失败响应的结果
                        error: function(data) {
                            alert("error！");
                        }
                    });
                }
        </script>
    </head>
    <body>
        增加一条学生记录<br><br>
        <form name="inputForm" action="${pageContext.request.contextPath}/student/studentAddSave" method="post">
            <table>
                    <tr>
                        <td>学号</td>
                        <td><input type="text" id="stuId" name="stuId" size=15></td>
                        <td><input type="button" value="验证" onclick="verifyStuId()" /></td>
                    </tr>
                    <tr>
                        <td>姓名</td>
                        <td><input type="text" name="stuName" size=15></td>
                    </tr>
                    <tr>
                        <td>班级</td>
                        <td><input type="text" name="stuClass" size=15></td>
                    </tr>
                    <tr>
                        <td>专业</td>
                        <td><input type="text" name="stuSpecial" size=15></td>
                    </tr>
                    <tr>
                        <td>年龄</td>
                        <td><input type="text" name="stuAge" size=15></td>
                    </tr>
                    <tr>
                        <td>性别</td>
                        <td><input type="radio" name="stuSex" value="男" checked>男
                            <input type="radio" name="stuSex" value="女" >女
                        </td>
                    </tr>
                    <tr>
                        <td>密码</td>
                        <td><input type="password" name="stuPassword" size=15></td>
                    </tr>
                    <tr>
                        <td></td>
                        <td><input type="submit" name="submit" value="提交" >
                            <input type="reset" name="reset" value="重置" >
                        </td>
                    </tr>
            </table>
        </form>
    </body>
</html>